home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / formats / kodak_cc / kodak_cc.frm
Internet Message Format  |  1980-02-06  |  5KB

  1. From johnston@george.lbl.gov Wed Apr 10 23:25:51 1991
  2. To: add@sciences.sdsu.edu, tiff@ucbvax.Berkeley.EDU
  3. Subject: Re:  Kodak YCC image file format
  4.  
  5. The file format is "icc", and there is nothing special about it.
  6. It is used for the 7700 high resolution printer, ans is basically
  7. just an rgb, byte/pixel file with a header.
  8. -------------------
  9. /*
  10. *NAME
  11. *     hipstoicc - convert hips file to icc (suitable for the kodak printer)
  12. *USAGE
  13. *     hipstoicc <in >out
  14. *DESCRIPTION
  15. *     Converts a hips file to an icc file which is suitable for the
  16. *     kodak XL7700 (true color and gray scale printer).
  17. *
  18. *     Hipstoicc handles only one frame.
  19. *
  20. *     The format for the output file is a monochrome ICC file,
  21. *     padded to 8-pixel in the column or x direction.
  22. *
  23. *     The format for the "ICC" header is:
  24. *
  25. *          Magic Number (5965600)          4 bytes
  26. *          Header Length                   4 bytes
  27. *          Extraneous data                 (Header Length -4) bytes
  28. *          Image File header length        4 bytes
  29. *          Header + data length            4 bytes
  30. *          Logical File Name              16 bytes 
  31. *          File Type (7)                   4 bytes
  32. *          Extraneous data                 8 bytes
  33. *          Image X Size                    4 bytes
  34. *          Image Y Size                    4 bytes
  35. *          Extraneous data                12 bytes
  36. *          Plane Count                     4 bytes
  37. *          Extraneous data                 8 bytes
  38. *          Extraneous data                 n bytes
  39. *          RED DATA (X_SIZE * Y_SIZE bytes)
  40. *          GREEN DATA (X_SIZE * Y_SIZE bytes) if needed
  41. *          BLUE DATA (X_SIZE * Y_SIZE bytes) if needed
  42. *
  43. *
  44. *    -Nancy Johnston, LBL - 24 Aug. 1990
  45. */
  46.  
  47. #include "hipl_format.h"
  48. #include <stdio.h>
  49. #include <time.h>         /* time defines            */
  50.  
  51. #define STDOUT 1
  52.  
  53.     /* input image declarations */
  54. unsigned char *start_in_image_buf_byte, *in_image_byte;
  55. int in_image_size_bytes ;
  56. int num_rows, num_cols, num_frames, image_size;
  57. long int x_col_pad;
  58. char *out_line;
  59. long  int header[128];         /* file header buffer */
  60. long  int clock;
  61. struct tm *date;
  62. int frame_num = 1;
  63.  
  64. char *Progname;
  65.  
  66. /*int out_fp;*/
  67.  
  68. main(argc,argv)
  69.  
  70. int argc;
  71. char **argv;
  72.  
  73. {
  74.     struct    header hd;
  75.     int i, j;
  76.  
  77.     Progname = strsave(*argv);
  78.     
  79.     read_header(&hd);
  80.     if(hd.pixel_format != PFBYTE)
  81.                 perr("pixel format must be bytes");
  82.     
  83.     num_rows = hd.rows;
  84.     num_cols = hd.cols;
  85.     x_col_pad = (num_cols + 7) & 0xfffffff8L;
  86.         /* allocated storage for one scan line */
  87.     out_line = (char *)calloc (x_col_pad, sizeof(char));
  88.     if (!out_line)
  89.     {
  90.     printf (" Could not allocated storage for scan line\n");
  91.     return (-1);
  92.     }
  93.         /* load outputted scanline with white */
  94.     for (i = 0; i < x_col_pad; ++i) out_line[i] = 255;
  95.         /* compute size of the image being read in */
  96.     image_size = num_rows * num_cols;
  97.     num_frames = hd.num_frame;
  98.     
  99.         /******  INITIALIZATION  ******/
  100.     for (i = 0; i < 128; i++)  header[i] = 0;
  101.     clock = time((long *)0);
  102.     date  = localtime(&clock);
  103.  
  104.   
  105.     header[0]  = 5965600;                        /* magic number */
  106.     header[1]  = 60;                             /* header length */
  107.     header[2]  = 0;                              /* no H/W version */
  108.     header[3]  = 0;                              /* no S/W version */
  109.                                                  /* creation date */
  110.     header[4]  = (((long)date->tm_year << 24)      & 0xff000000L) +
  111.                  (((long)(date->tm_mon + 1) << 16) & 0x00ff0000L) +
  112.                  (((long)date->tm_mday << 8)       & 0x0000ff00L) +
  113.                   ((long)date->tm_hour             & 0x000000ffL);
  114.     header[5]  = (((long)date->tm_min << 24) & 0xff000000L) +
  115.                  (((long)date->tm_sec << 16) & 0x00ff0000L);
  116.   
  117.     header[6]  = 0;                              /* no update date */
  118.     header[7]  = 0;
  119.     header[8]  = 0x64656d6fL;                    /* user name ("demo") */
  120.   
  121.     header[16] = 80;                             /* subfile header length */
  122.     header[17] = header[16] + (x_col_pad * num_rows); /* subfile length */
  123.     header[22] = 7;                              /* file type */
  124.     header[25] = num_cols;                       /* image x size */
  125.     header[26] = num_rows;                       /* image y size */
  126.     header[29] = 1;                              /* gray scale */
  127.     header[30] = 1;                              /* plane count */
  128.     write(STDOUT,header,144);
  129.   
  130.         /****** READ IN HIPS FILE ******/
  131.     start_in_image_buf_byte = (unsigned char*) halloc(image_size, sizeof (char));
  132.     in_image_byte = start_in_image_buf_byte;
  133.     in_image_size_bytes = image_size * (sizeof(char));
  134.     if ((i = pread(0, start_in_image_buf_byte, in_image_size_bytes))
  135.       != in_image_size_bytes)
  136.     perr("Unexpected end-of-file in frame number %d. %d bytes \
  137.     read for this frame.", frame_num, i);
  138.     in_image_byte = start_in_image_buf_byte; /* set pointer to start of image */
  139.  
  140.         /****** write out each row padding to 8 bits because thats what
  141.             icc or kodak wants ******/
  142.     for (i=0; i < num_rows; ++i)
  143.     {
  144.     for (j = 0; j < num_cols; j++)
  145.         out_line[j] = *in_image_byte++;
  146.     write (STDOUT, out_line, x_col_pad);
  147.     }
  148. }
  149.  
  150.